import { CellType, FieldType, RgvRoadOrientation, SiteOrientation, SrmOrientation } from "./enums";

export interface FieldValueMap {
  Id: string;
  Key: number,
  Description: string;
  Color: string;
}

export interface FieldMapConfig {
  Id: string;
  Name: string;
  Description?: string;
  Address?: string;
  Type?: FieldType;
  FontSize?: number;
  Visible: boolean;
  Maps: FieldValueMap[];
}

export interface CellConfig {
  Id?: string;
  Name?: string;
  X?: number;
  Y?: number;
  Width?: number;
  Height?: number;
  Type: CellType;
}

export interface ScenarioConfig {
  Id?: string;
  Name?: string;
  Lines: PiplineConifg[];
  Srms: SrmConfig[];
  Boards: MonitorBoardConfig[];
  Rgvs: RgvConfig[];
}

export interface ScenarioPreivewVM {
  Id: string;
  Name: string;
  IsAlive: boolean;
  CreatedOn: Date;
  UpdatedOn?: Date;
}

export interface PiplineConifg extends CellConfig {
  Sites: SiteNodeConfig[];
  Plc: PlcConfig;
  Status: FieldMapConfig;
}

export interface PlcConfig {
  /** IP地址 */
  Ip: string;
  /** 端口 */
  Port: number;
  /**时间间隔（毫秒） */
  Interval: number;
}

export interface SiteNodeConfig extends CellConfig {
  ParentId: string;
  Orientation: SiteOrientation;
  Status: FieldMapConfig;
  Fields: FieldMapConfig[];
}

export interface LaneConfig {
  Orientation: SrmOrientation;
  /**
   * 最小列
   */
  MinColumn: number;
  /**
   * 最大列
   */
  MaxColumn: number;
  /**
   * 是否显示
   */
  IsVisible: boolean;
  /**
   * 是否双深位
   */
  DoubleLine: boolean;

  SrmField?: string;

  OffsetMax?: number;

  OffsetMin?: number;
}

export interface SrmConfig extends CellConfig {
  Plc: PlcConfig;
  Fields: FieldMapConfig[];
  Status: FieldMapConfig;
  Lane: LaneConfig;
}

export interface RgvRoadConfig {
  Orientation: RgvRoadOrientation;
  OffsetMin: number;
  OffsetMax: number;
  RgvField: string;
}

export interface RgvConfig extends CellConfig {
  Plc: PlcConfig;
  Status: FieldMapConfig;
  Fields: FieldMapConfig[];
  Road: RgvRoadConfig;
}

export interface MonitorBoardConfig extends CellConfig {
  Plc: PlcConfig;
  Fields: FieldMapConfig[];
}

export type NodeConfig = PiplineConifg | SiteNodeConfig | SrmConfig | MonitorBoardConfig;


export interface FieldUpdatedEvent {
  TargetId: string;
  Values: { [key: string]: any; };
}

export interface ScenarioChangedEvent {
  ScenarioId: string;
}

export interface ScenarioLoadedEvent {
  ScenarioId: string;
}

export interface ScenarioUnloadedEvent {
  ScenarioId: string;
}

export class SignalRConfig {
  baseUrl!: string;
  constructor() {
    this.baseUrl = "/testudo/hubs/wcs-proxy";
  }
}

export interface ColorSuit {
  Color: string;
  Description: string;
}


export interface GraphViewportSettings {
  scale?: {
    sx: number,
    sy: number,
    ox: number,
    oy: number;
  },
  translate?: {
    tx: number,
    ty: number;
  };
}